import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/5 16:12
 * @description 利用HashSet存储word，如果发现某个单词出现在其他单词的后缀中，那么整个单词肯定不需要编码进去
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minimumLengthEncoding(String[] words) {
        Set<String> good = new HashSet<String>(Arrays.asList(words));
        for (String word: words) {
            for (int k = 1; k < word.length(); ++k) {
                good.remove(word.substring(k));
            }
        }

        int ans = 0;
        for (String word: good) {
            ans += word.length() + 1;
        }
        return ans;
    }
}
